# 需求：
#    1. 打开register.html
#    2. 点击 注册A网页
#    3. 填写 注册A网页 内容
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
driver.maximize_window()
url = 'file:///root/NSD2408/html/register.html'
driver.get(url)
# 点击A网页链接
sleep(3)
driver.find_element(By.PARTIAL_LINK_TEXT, 'A网页').click()
# 获取所有的窗口句柄
windows = driver.window_handles
# 获取主窗口句柄
main = driver.current_window_handle
print('所有窗口：', windows)
print('主窗口：', main)
# 排除主窗口，剩下的就是新窗口句柄
for item in windows:
    if item != main:
        # 切换到新窗口
        driver.switch_to.window(item)
        # 输入内容
        driver.find_element(By.CSS_SELECTOR, '#userA').send_keys('admin')
        driver.find_element(By.CSS_SELECTOR, '#passwordA').send_keys('123456')
        driver.find_element(By.CSS_SELECTOR, '#telA').send_keys('18812345678')
        driver.find_element(By.CSS_SELECTOR, '#emailA').send_keys('123@qq.com')
        # 获取新窗口信息
        print('标题：', driver.title)
        sleep(3)
        # 关闭新窗口
        driver.close()
sleep(3)
driver.quit()